package 代码记录.指定公司代码练习记录.西安.分值100分;

import java.util.Scanner;

/**
 * @author zx
 * @create 2023-07-08 12:21
 * 改进人家的思路
 */
public class 找终点 {//46--copy
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] temp = str.split(" ");
        int[] arr = new int[temp.length];
        for(int i = 0;i < arr.length;i++){
            arr[i] = Integer.parseInt(temp[i]);
        }
        int right = arr.length / 2;
        int res = Integer.MAX_VALUE;
        for(int i = 2;i < right;i++){
            int count = 1;//第一步固定
            int cur = i;
            while(cur < arr.length - 1){
                cur += arr[cur];
                count++;
                if(cur == arr.length - 1){
                    res = Math.min(res,count);
                    break;
                }
                if(cur > arr.length - 1){
                    break;
                }
            }
        }
        if(res <= arr.length){
            System.out.println(res);
        }else{
            System.out.println(-1);
        }
    }
}
